package leetcode.other;

import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 李栋
 * @version 1.0.0
 * @className Test0804.java
 * @createTime 2021年08月01日 21:12:00
 */
public class Test0804 {

    private static final Logger logger = LoggerFactory.getLogger(Test0804.class);


    @Test
    public void test() {
        int[] num = {1, 2, 3};
        List<List<Integer>> subsets = subsets(num);
        logger.info(String.valueOf(subsets));
    }

    public List<List<Integer>> subsets(int[] nums) {
        List<Integer> list = new ArrayList<>();
        List<List<Integer>> res = new ArrayList<>();
        backtrack(nums, 0, list, res);
        return res;
    }

    private void backtrack(int[] nums, int cur, List<Integer> list, List<List<Integer>> res) {
        res.add(new ArrayList<>(list));
        for (int i = cur; i < nums.length; ++i) {
            list.add(nums[i]);
            backtrack(nums, i + 1, list, res);
            list.remove(list.size() - 1);
        }
    }


}
